local skel = fk.CreateSkill {
  name = "efengqi__huairou",
}

Fk:loadTranslationTable{
  ["efengqi__huairou"] = "怀柔",
  [":efengqi__huairou"] = "出牌阶段限三次，你可以重铸一张非基本牌。若不为装备牌，你可以使用此牌。",

  ["#efengqi__huairou"] = "怀柔：重铸一张牌，若不为装备可以使用之",
  ["#efengqi__huairou-use"] = "怀柔：你可以使用这张牌",

  ["$efengqi__huairou1"] = "各保分界，无求细利。",
  ["$efengqi__huairou2"] = "胸怀千万，彰其德，包其柔。",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  prompt = "#efengqi__huairou",
  times = function(self, player)
    return player.phase == Player.Play and 3 - player:usedSkillTimes(self.name, Player.HistoryPhase) or -1
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
  end,
  card_filter = function (self, player, to_select, selected)
    if #selected == 0 then
      if Fk:getCardById(to_select).type ~= Card.TypeBasic then
        return true
      end
      if player:getMark("efengqi__jueyan1") > 0 and
        Fk:getCardById(to_select).trueName == "slash" then
        return true
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    if player:getMark("efengqi__jueyan2") > 0 and Fk:getCardById(effect.cards[1]).type == Card.TypeEquip then
      player:addSkillUseHistory(self.name, -1)
    end
    room:recastCard(effect.cards, player, self.name)
    if not player.dead and table.contains(room.discard_pile, effect.cards[1]) and
    Fk:getCardById(effect.cards[1]).type ~= Card.TypeEquip then
      room:askToUseRealCard(player, {
        skill_name = skel.name, pattern = effect.cards, prompt = "#efengqi__huairou-use",
        extra_data = {
          bypass_times = true,
          extraUse = true,
          expand_pile = effect.cards,
        },
      })
    end
  end,
})

return skel
